package com.gid.rcflightlogger;

import java.util.Date;

import android.content.Context;

import com.orm.androrm.BooleanField;
import com.orm.androrm.DateField;
import com.orm.androrm.ForeignKeyField;
import com.orm.androrm.IntegerField;
import com.orm.androrm.Model;
import com.orm.androrm.QuerySet;

public class Flight extends Model {
	
	public static final QuerySet<Flight> objects(Context context) {
		return objects(context, Flight.class);
	}
	
	public static final int OUTCOME_CODE_OK = 0;
	public static final int OUTCOME_CODE_LIGHT_DAMAGE = 1;
	public static final int OUTCOME_CODE_HEAVY_DAMAGE = 2;
	public static final int OUTCOME_CODE_OMG = 3;
	
	public static final String[] FLIGHT_OUTCOME_LABELS = {"Landed safely :-)", "Light crash :-|", "Heavy crash :-(", "OMG!!!"}; //mapped to indices in codes above
	public static final String[] FLIGHT_OUTCOME_SYMBOLS = {"", ":-|", ":-(", ":(("}; //mapped to indices in codes above
	
	protected IntegerField mCount;
	protected IntegerField mDuration; //in seconds
	protected DateField mDate; //YYYY-MM-DDTHH:MM:SS
	protected IntegerField mOutcome;
	protected BooleanField mFake; //if true is a fake entry
	protected ForeignKeyField<Aircraft> mAircraft;
	//constructor
	public Flight() {
		super();
		
		mCount = new IntegerField();
		mDuration = new IntegerField();		
		mDate = new DateField();
		mOutcome = new IntegerField();
		mFake = new BooleanField();
		mAircraft = new ForeignKeyField<Aircraft>(Aircraft.class);
		reset();
	}
	
	//reset all fields to default value
	public void reset()
	{
		mCount.set(1);
		mDuration.set(0);
		mDate.set(new Date());
		mFake.set(false);
		mOutcome.set(OUTCOME_CODE_OK);		
	}

	//member access methods
	public int getCount() {
		return mCount.get();
	}
	
	public void setCount(int count) {
		mCount.set(count);
	}
	
	public int getDuration() {
		return mDuration.get();
	}
	
	public void setDuration(int duration) {
		mDuration.set(duration);
	}
	
	public Date getDate() {
		return mDate.get();
	}
	
	public void setDate(Date d) {
		mDate.set(d);
	}
	
	public int getOutcome() {
		return mOutcome.get();
	}
	
	public void setOutcome(int o) {
		mOutcome.set(o);
	}
	
	public boolean getFake() {
		return mFake.get();
	}
	
	public void setFake(boolean status) {
		mFake.set(status);
	}
	
	public Aircraft getAircraft(Context context) {
		return mAircraft.get(context);
	}
	
	public void setAircraft(Aircraft ac) {
		mAircraft.set(ac);
	}
}
